package top.shiyiri.dao.impl;

import top.shiyiri.dao.BaseDao;
import top.shiyiri.dao.UserDao;
import top.shiyiri.pojo.User;

import java.util.List;

/**
 * @author Aunean
 * @date 2022/1/28 18:27
 */
public class UserDaoImpl extends BaseDao implements UserDao {
    @Override
    public User queryUserByUsername(String username) {
        String sql = "select * from t_user where username = ?";
        return QueryForOne(User.class, sql, username);
    }

    @Override
    public int saveUser(User user) {
        String sql = "insert into t_user(username,password,email) values(?,?,?)";
        return update(sql, user.getUsername(), user.getPassword(), user.getEmail());
    }

    @Override
    public User queryUserByUsernameAndPassword(String username, String password) {
        String sql = "select * from t_user where username = ? and password = ?";
        return QueryForOne(User.class, sql, username, password);
    }

    @Override
    public List<User> queryUserList() {
        String sql = "select * from t_user";
        return queryForList(User.class, sql);
    }
}
